﻿using System;
using System.Data;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using AnyOffice.Components;
using AnyOffice.DAL;
using AnyOffice.Model;

namespace AnyOffice.general.person_info
{
    public partial class url_edit : ModulePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.Page.IsPostBack)
            {
                int urlId = (Request.QueryString["url_id"] == null) ? 0 : int.Parse(Request.QueryString["url_id"].ToString());
                this.ViewState["UrlId"] = urlId;
                DataTable table = new UrlDao().SelectByUrlId(base.Conn, urlId, base.User.Identity.Name);
                if (table.Rows.Count > 0)
                {
                    this.txtUrlNo.Text = (table.Rows[0]["UrlNo"] != DBNull.Value) ? table.Rows[0]["UrlNo"].ToString() : "";
                    this.txtUrlDesc.Text = (table.Rows[0]["UrlDesc"] != DBNull.Value) ? table.Rows[0]["UrlDesc"].ToString() : "";
                    this.txtUrl.Text = (table.Rows[0]["Url"] != DBNull.Value) ? table.Rows[0]["Url"].ToString() : "";
                }
                else
                {
                    this.pnlMain.Visible = false;
                    this.litMessage.Text = base.ShowPrompt("无此网址！", "url.aspx");
                }
            }
            if (this.Page.IsPostBack)
            {
                UrlDao dao2 = new UrlDao();
                UrlData data = new UrlData();
                data.UserId = base.User.Identity.Name;
                data.UrlId = Convert.ToInt32(this.ViewState["UrlId"]);
                data.UrlNo = Convert.ToInt32(this.txtUrlNo.Text);
                data.UrlDesc = this.txtUrlDesc.Text;
                data.Url = this.txtUrl.Text;
                dao2.Update(base.Conn, data);
                base.CloseConn();
                Response.Redirect("url.aspx");
            }
        }
 

    }
}
